package com.senlingspace.web.controller.headquarters;

import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.annotation.RepeatSubmit;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.core.page.TableDataInfo;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjProductType;
import com.senlingspace.system.domain.vo.SlkjProductTypeVo;
import com.senlingspace.system.service.ISlkjProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类别Controller
 * 
 * @author wangliang
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/system/productType")
public class SlkjProductTypeController extends BaseController
{
    @Autowired
    private ISlkjProductTypeService slkjProductTypeService;

    /**
     * 查询商品类别列表
     */
    @PreAuthorize("@ss.hasPermi('system:productType:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjProductType slkjProductType)
    {
        List<SlkjProductType> list = slkjProductTypeService.selectSlkjProductTypeList(slkjProductType);
        return getDataTable(list);
    }

    // /**
    //  * 导出商品类别列表
    //  */
    // @PreAuthorize("@ss.hasPermi('system:productType:export')")
    // @Log(title = "商品类别", businessType = BusinessType.EXPORT)
    // @PostMapping("/export")
    // public void export(HttpServletResponse response, SlkjProductType slkjProductType)
    // {
    //     List<SlkjProductType> list = slkjProductTypeService.selectSlkjProductTypeList(slkjProductType);
    //     ExcelUtil<SlkjProductType> util = new ExcelUtil<SlkjProductType>(SlkjProductType.class);
    //     util.exportExcel(response, list, "商品类别数据");
    // }

     /**
      * 获取商品类别详细信息
      */
     @PreAuthorize("@ss.hasPermi('system:productType:query')")
     @GetMapping(value = "/{typeId}")
     public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
     {
         return success(slkjProductTypeService.selectSlkjProductTypeByTypeId(typeId));
     }

    /**
     * 新增商品类别
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('system:productType:add')")
    @Log(title = "商品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjProductType slkjProductType)
    {
        return toAjax(slkjProductTypeService.insertSlkjProductType(slkjProductType));
    }

    /**
     * 修改商品类别
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('system:productType:edit')")
    @Log(title = "商品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjProductType slkjProductType)
    {
        return toAjax(slkjProductTypeService.updateSlkjProductType(slkjProductType));
    }

    /**
     * 删除商品类别
     */
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PreAuthorize("@ss.hasPermi('system:productType:remove')")
    @Log(title = "商品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long typeIds)
    {
        return toAjax(slkjProductTypeService.deleteSlkjProductTypeByTypeId(typeIds));
    }


    /**
     * 商品类型下拉列表
     */
    @GetMapping("/selectCheck")
    public TableDataInfo selectCheck()
    {
        List<SlkjProductTypeVo> list = slkjProductTypeService.selectCheck();
        return getDataTable(list);
    }
}
